package main

type UIDSet map[UID]bool

func makeUIDSet(uids ...UID) UIDSet {
	set := make(UIDSet, len(uids))
	for _, uid := range uids {
		set[uid] = true
	}
	return set
}

func (set UIDSet) Add(uids ...UID) UIDSet {
	for _, uid := range uids {
		set[uid] = true
	}
	return set
}

func (set UIDSet) Remove(uids ...UID) UIDSet {
	for _, uid := range uids {
		set[uid] = false
	}
	return set
}

func (s1 UIDSet) Union(s2 UIDSet) UIDSet {
	for uid := range s2 {
		s1[uid] = s1[uid] || s2[uid]
	}
	return s1
}

func (s1 UIDSet) Intersection(s2 UIDSet) UIDSet {
	for uid := range s1 {
		s1[uid] = s1[uid] && s2[uid]
	}
	return s1
}

func (set UIDSet) UIDs() UIDs {
	uids := make(UIDs, 0, len(set))
	for uid, ok := range set {
		if ok {
			uids = append(uids, uid)
		}
	}
	return uids
}
